<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge"> 
    <!-- 是标题上面的小图标 -->
    <link rel="shortcut icon" href="#">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/loading.css">
    <script src="js/jquery-3.1.1.min.js"></script>
    <title>loading</title>
</head>
<body>
    <div class="head">
            <span class="title">在线驾考模拟系统</span>
            <ul>
                <li><a href="loading.html">登录</a></li>
                <li><a href="register.html">注册</a></li>
            </ul>      
        </div>
    
        <div class="nav">
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="order_exercise.html">顺序练题</a></li>
                <li><a href="error_book.html">错题本</a></li>
                <li><a href="mock_exam.html">模拟测试</a></li>
                <li><a href="message.html">留言板</a></li>
            </ul>
        </div>

        <div class="content">
            <div class="container">
                <div class="container-left">
                    <span>请先登录您的账号！</span>
                </div>
                <div class="container-center"></div>
                <div class="container-right">
                    <ul>
                        <li>用户名:&nbsp;&nbsp;
                            <input type="text" id="name" onfocus="javascript:this.value=''" >
                        </li>
                        <li>密&nbsp;&nbsp;&nbsp;码：
                            <input type="password" id="psw" onfocus="javascript:this.value=''" >
                        </li>
                    </ul>
                <p>
                    <input type="checkbox">记住用户名
                    <a href="#">忘记密码?</a>
                </p>
                <button class="loading-btn" id="btn1" onclick="checkform()">登录</button>
                </div>
            </div>
        </div>
        <script>
        document.title = '驾考网站'
        function checkform(){ 
			var name = document.getElementById('name').value
			var pwd = document.getElementById('psw').value
            if(name.length==0){    
                alert('用户名不能为空！');
                document.getElementById('name').focus();
                return false;
            }
            if(pwd.length==0){    
                alert('密码不能为空！');
                document.getElementById('psw').focus();
                return false;
            }
			request({
				name: name,
				password: pwd
			})
        }
        function request(data) {
			$.ajax({
				url: "/api/login/addAuthinfo",           
				dataType: "json",
				async: "true",
				method: "POST",
				data:data,
				success:function(data) {
                    console.log(data)
					if(data.status === 'success'){
                        // debugger;   
                        localStorage.setItem('name',data.msg.user_name)
                        localStorage.setItem('user_id', data.msg.user_id)
                        console.log('user_id', data.msg.user_id)
                        localStorage.setItem('login_symbol', '1')
                        location.href = 'index.html'
                    }                                   
                },               
                error:function(e){
                    console.log(e)
                }
                        
			}) 
		}
        </script>
</body>
</html>